function r = softmax(x)
    S = sum(exp(x));
    r = zeros(length(x), 1);
    for i = 1:length(x)
        r(i) = exp(x(i)) / S;
    end
end